package bizlogic;

import DAO.*;
import model.*;

import java.util.*;

public class Manager {
	private UserDAO userDAO;
	private FacilitiesDAO facilitiesDAO;
	private BookDetailsDAO bookdetailsDAO;
	private FacilitiesDTO facilityDTO;
	
	public Manager() {
		userDAO = DAOFactory.loadInstance().getUserDAO();
		facilitiesDAO=DAOFactory.loadInstance().getFacilitiesDAO();
		bookdetailsDAO = DAOFactory.loadInstance().getBookDetailsDAO();
	}

	public boolean Isvalid(String FID)
	{   boolean result=true;
	    boolean wrgresult=false;
	    try {
			result=facilitiesDAO.IsValid(FID);
		} catch (NotFoundException e) {
			e.printStackTrace();
		}
		if(result==true)
		{
			return result;
		}
		else
			return wrgresult;
	}
	@SuppressWarnings("finally")
	public UserDTO findbyId(int userId){
		UserDTO currentUser = new UserDTO();
		try {
			currentUser = userDAO.findbyId(userId);
		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally
		{
			return currentUser;
		}
	}
    
    public void insertUser(UserDTO user) {
    	try {
    		userDAO.insertUser(user);
		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    public void updateUser(UserDTO user) {
    	try {
    		userDAO.updateUser(user);
		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    public void deleteUser(UserDTO user) {
    	try {
    		userDAO.deleteUser(user);
		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    @SuppressWarnings("finally")
	public ArrayList<FacilitiesDTO> FindAllFacilities(){
    	ArrayList<FacilitiesDTO> currentList=new ArrayList<FacilitiesDTO>();
    	try{
    		currentList=facilitiesDAO.FindAll();
    	}
    	catch(NotFoundException e){
    		e.printStackTrace();
    	}finally{
    		return currentList;
    	}
    }
    @SuppressWarnings("finally")
	public ArrayList<FacilitiesDTO> FindByFacilitiesType(String Type){
    	ArrayList<FacilitiesDTO> currentList=new ArrayList<FacilitiesDTO>();
    	try{
    		currentList=facilitiesDAO.FindByType(Type);
    	}
    	catch(NotFoundException e)
    	{
    		e.printStackTrace();
    	}finally{
    		return currentList;
    	}	
    }
    @SuppressWarnings("finally")
	public FacilitiesDTO findFacility(Integer id){
    	FacilitiesDTO f=new FacilitiesDTO();
    	try{
    		f=facilitiesDAO.findFacility(id);
    	}
    	catch(NotFoundException e)
    	{
    		e.printStackTrace();
    	}finally{
    		return f;
    	}	
    }
    public void insert(FacilitiesDTO facilitiesft) {
    	try{
    	facilitiesDAO.insertFacilities(facilitiesft);
    	}
    	catch(NotFoundException e){
    		e.printStackTrace();
    	}
    }
    public void update(FacilitiesDTO facilitiesft){
    	try{
    		facilitiesDAO.updateFacilities(facilitiesft);
    	}
    	catch(NotFoundException e){
    		e.printStackTrace();
    	}
    }
    public void delete(FacilitiesDTO facilitiesft){
    	try{
    		facilitiesDAO.deleteFacilities(facilitiesft);
    	}
    	catch(NotFoundException e){
    		e.printStackTrace();
    	}
    }
    
    //BookDetails - Shivangi
    
    public void insert(BookDetailsDTO book) {
    	try {
    		bookdetailsDAO.insert(book);
		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    public void update(BookDetailsDTO book) {
    	try {
    		bookdetailsDAO.update(book);
		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    public void delete(BookDetailsDTO book) {
    	try {
    		bookdetailsDAO.delete(book);
		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    public void cancel(BookDetailsDTO book) {
    	try {
    		bookdetailsDAO.cancel(book);
		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    public BookDetailsDTO FindByBookingID(int bookingID) {
    	BookDetailsDTO bd = new BookDetailsDTO();
    	try {
    		bd = bookdetailsDAO.FindByBookingID(bookingID);
		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return bd;
    }
    @SuppressWarnings("finally")
	public ArrayList<BookDetailsDTO> findBookingHistory(BookDetailsDTO book) {
    	ArrayList<BookDetailsDTO> currentList = new ArrayList<BookDetailsDTO>();
    	try {
    		currentList = bookdetailsDAO.findBookingHistory();

		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally
		{
			return currentList;
		}
    }
    @SuppressWarnings("finally")
	public ArrayList<BookDetailsDTO> findAwaitingApproval(BookDetailsDTO book) {
    	ArrayList<BookDetailsDTO> currentList = new ArrayList<BookDetailsDTO>();
    	try {
    		currentList = bookdetailsDAO.findAwaitingApproval();

		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally
		{
			return currentList;
		}
    }
}
